package kr.saeildamil.androidstudty.ch12;

import kr.saeildamil.androidstudty.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

public class SpinnerTest extends Activity {
	ArrayAdapter<CharSequence> adspin;
	boolean mInitSpinner;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch12_spinnertest);
		
		Spinner spin = (Spinner) findViewById(R.id.ch12_spinnertest_spin);
		spin.setPrompt("나라를 선택하세요");
		
		adspin = ArrayAdapter.createFromResource(this, R.array.country, android.R.layout.simple_spinner_item);
		adspin.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		
		
		spin.setAdapter(adspin);
		spin.setSelection(5);
		int pos = spin.getSelectedItemPosition();
		Toast.makeText(this, "pos : " + pos, Toast.LENGTH_LONG).show();
/*		spin.setOnItemSelectedListener(new OnItemSelectedListener() {
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				if (mInitSpinner == false){
					mInitSpinner = true;
					return;
				}
				Toast.makeText(SpinnerTest.this, adspin.getItem(position), Toast.LENGTH_LONG).show();
			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {}
		});*/
	}
}
